package Compare;

import java.util.Comparator;
import java.util.PriorityQueue;

class IntCmp implements Comparator<Integer>{
    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }//以大根堆来进行
}

public class Test {
    public static int[] smallestK(int[] arr,int k){
        int[] ret = new int[k];
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        for (int i=0;i<arr.length;i++){
            priorityQueue.offer(arr[i]);
        }
        for (int i=0;i<k;i++){
            ret[i] =priorityQueue.poll();
        }
        return ret;
    }
}
